<section id="registration"> 
  <section class="welcome">
  </section>

	<section class="registration">
	<h2><%=t('devise.invitations.edit.header', {:community_name => Vish::Application.config.name})%></h2>

	<%= form_for resource, :as => resource_name, :url => user_invitation_path(), :html => { :method => :put } do |f| %>
	  <%= devise_error_messages! %>
	  <%= f.hidden_field :invitation_token %>
	  <div class="reg-labels">
	  <%= f.label :name %>
	  <%= f.text_field :name, :class =>"form_tag", :autocomplete => "off" %>
	        
	  <%= f.label :email %>
	  <%= f.text_field :email, :class =>"form_tag", :autocomplete => "off", :value => resource.email %>
	  
	  <%= f.label :password %>
	  <%= f.password_field :password %>

	  <%= f.label :password_confirmation %>
	  <%= f.password_field :password_confirmation %>
		
		<%= f.label t('profile.occupation.label') %>
        <%= f.select(:occupation, options_for_select([[t('profile.occupation.options.select'), 0], [t('profile.occupation.options.teacher'), 1],[t('profile.occupation.options.scientist'),2], [t('profile.occupation.options.other'),3]], params[:user] ? params[:user][:occupation]:nil)) %>

        <%= f.label t('activerecord.attributes.user.tag') %>
        <div class="tagBoxNew">
          <ul class="tagList"></ul>
        </div>
        <%= f.hidden_field :tag_list, :class => "form_tag", :id => "input_tag_list", :placeholder => t('devise.tags')   %>
        <% @tags = ActivityObject.tag_counts(:limit => 100, :order => "count desc")%>
        <ul id="preloadTagList" style="display:none">
          <%@tags.each do |tag| %>
            <li>
              <%=tag.name%>
            </li>
          <%end%>
        </ul>
        
        <hr class="soften">
        <div class="conditions">
          <%= t('conditions.check_message') %>

          <%= link_to t('conditions.check_message_1'), '/legal_notice', :target=>'_blank' %>

          <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
            <%= link_to t('confirmation.not_received.long'), new_confirmation_path(resource_name) %>.
          <% end -%>
        </div>

        <%= f.submit t('action.accept').capitalize,:class=>"btn pull-right"%>
      </div>

      <hr class="soften">
      <%= render :partial => "devise/shared/links" %>
      
    <% end %>
  </section>
</section>
	  


<%= content_for :javascript do %>
    var tagList = $(".tagList");
    var tags = [];

    //Load tags
    $.each($("#preloadTagList li"), function(index, element) {
       tags.push($(element).html());
    });

    $(tagList).tagit({
      tagSource:tags, 
      sortable:true, 
      maxLength: '<%=Vish::Application.config.tagsSettings["maxLength"]%>',
      maxTags: '<%=Vish::Application.config.tagsSettings["maxTags"]%>',
      triggerKeys: <%=raw(Vish::Application.config.tagsSettings["triggerKeys"].to_json)%>,
      watermarkAllowMessage: '<%=t('document.tags.areasOfInterestMessage')%>',
      watermarkDenyMessage: '<%=t('document.tags.limitMessage')%>',
      initialTags: <%=(params[:user] && params[:user][:tag_list]) ? raw(params[:user][:tag_list].split(",")) : "[]" %>,
      tagsChanged:function (tag, action) {
        //Check if the element popped is a suggestion
        if(action=="popped"){
          $.each($(".tagit-suggestions li"), function(index, element) {
            if($(element).html()==tag){
              $(element).show();
            }
          });
        }
      } 
    });

    //Allow suggestions
    $(".tagit-suggestions li").on("click", function(){
      var result = $(".tagit").tagit('add', $(this).html() );
      if(result==true){
        $(this).hide();
      }
    });

    //Fill tag_list hidden input before send
     var button = $("input[type='submit'][class='btn pull-right']");
      $(button).click(function(event) {
       var tagList = $(".tagList");
       $("#input_tag_list").val(Vish.Utils.convertToTagsArray($(tagList).tagit("tags")));
       return true;
     });

<% end %>
